<?php
/**
 * 25 September 2007
 * JoomlaLMS Installation Helper 1.1
 * 
 * Powered by JoomlaLMS
 * 
 * * *
 * Put this file into your Joomla root directory.
 */
@set_time_limit(3600);
if (!defined('_JEXEC')) { define( '_JEXEC', 1 ); }
if (!defined('JPATH_BASE')) { define('JPATH_BASE', dirname(__FILE__) ); }
if (!defined('DS')) { define( 'DS', DIRECTORY_SEPARATOR ); }

$step = isset($_REQUEST['step'])? $_REQUEST['step'] : '';
if (!in_array($step, array('image_tr','image_tl','image_t','image_br','image_bl','image_b','image_tick','image_error','image_warning','image_back','image_forward', 'getcss'))) {
	$joomla_10 = false;
	$joomla_15 = false;
	$GLOBALS['joomla_old'] = true;
	if (file_exists(JPATH_BASE.'/includes/joomla.php') && file_exists(JPATH_BASE.'/globals.php') && file_exists(JPATH_BASE.'/configuration.php')) {
		$joomla_10 = true;
	}
	if (file_exists(JPATH_BASE.'/includes/joomla.php') && file_exists(JPATH_BASE.'/configuration.php') && file_exists(JPATH_BASE.'/libraries/loader.php')) {
		$joomla_15 = true;
		$GLOBALS['joomla_old'] = false;
	}
	if ($joomla_10) {
		if (!defined('_VALID_MOS')) { define( '_VALID_MOS', 1 ); }
		include_once( 'globals.php' );
		require_once( 'configuration.php' ); //load Joomla config variables
		if (file_exists($mosConfig_absolute_path . '/includes/mambo.php')) { //check if our site based on Mambo
			$isMambo = true;
			require_once( $mosConfig_absolute_path . '/includes/mambo.php' );
		} elseif (file_exists($mosConfig_absolute_path . '/includes/joomla.php')) {
			$isMambo = false; //we use Joomla!
			require_once( $mosConfig_absolute_path . '/includes/joomla.php' );
		}

		if (file_exists( $mosConfig_absolute_path . "/language/" . $mosConfig_lang . ".php" )) {
			include_once( $mosConfig_absolute_path . "/language/" . $mosConfig_lang . ".php" );
		} else {
			include_once( $mosConfig_absolute_path . "/language/english.php" );
		}
		$database = new database( $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix );
		$mainframe = new mosMainFrame( $database, '', '.' );
		$mainframe->initSession();
		$my = $mainframe->getUser();
		require_once($mainframe->getCfg('absolute_path')."/administrator/includes/pcl/pclzip.lib.php");
		require_once($mainframe->getCfg('absolute_path') . '/administrator/includes/pcl/pclerror.lib.php' );
	} elseif ($joomla_15) {
		require_once( JPATH_BASE .DS.'includes'.DS.'defines.php' );
		require_once( JPATH_BASE .DS.'includes'.DS.'framework.php' );
		//require_once( JPATH_BASE .DS.'includes'.DS.'helper.php' );

		//JDEBUG ? $_PROFILER->mark( 'afterLoad' ) : null;
		if (class_exists('JApplication')) {
			$mainframe =& JApplication::getInstance('site');
		} else {
			$mainframe =& JFactory::getApplication('site');
		}

		if (!class_exists('JPluginHelper')) { // J1.5RC4 compat
			$mainframe->initialise();
		}

		JPluginHelper::importPlugin('system');
		require_once(JPATH_BASE.DS.'administrator'.DS.'includes'.DS.'pcl'.DS.'pclzip.lib.php');
		require_once(JPATH_BASE.DS.'administrator'.DS.'includes'.DS.'pcl'.DS.'pclerror.lib.php' );
	} else {
		LH_MainPage();
		die;
	}
	$GLOBALS['joomla_old'] = true;
	if (file_exists(JPATH_BASE.'/includes/joomla.php') && file_exists(JPATH_BASE.'/globals.php') && file_exists(JPATH_BASE.'/configuration.php')) {
		$joomla_10 = true;
	}
	if (file_exists(JPATH_BASE.'/includes/joomla.php') && file_exists(JPATH_BASE.'/configuration.php') && file_exists(JPATH_BASE.'/libraries/loader.php')) {
		$joomla_15 = true;
		$GLOBALS['joomla_old'] = false;
	}
}
$step = isset($_REQUEST['step'])? $_REQUEST['step'] : '';
switch ($step) {
	case 'image_tr':
	case 'image_tl':
	case 'image_t':
	case 'image_br':
	case 'image_bl':
	case 'image_b':
	case 'image_tick':
	case 'image_error':
	case 'image_warning':
	case 'image_back':
	case 'image_forward':
		LH_ShowImage($step);
	break;
	case 'getcss':
		LH_GetCSS();
	break;
	case 'preinstall':
		LH_PreInstallCheck();
	break;
	case 'install':
		LH_DoInstall();
	break;
	default:
		LH_MainPage();
	break;
}

function LH_DoInstall() {
	global $joomla_old;
	LH_ShowBegin();
	if ($joomla_old) {
		if (function_exists('josSpoofValue')) {
			$_POST[josSpoofValue()] = 1;
		}
		global $database;
	} else {
		$database = & JFactory::getDBO();
	}
	if ($joomla_old) {
		require_once(JPATH_BASE.'/administrator/includes/admin.php' );
		require_once(JPATH_BASE.'/includes/domit/xml_domit_lite_include.php' );
		require_once(JPATH_BASE.'/administrator/components/com_installer/installer.class.php');
		require_once(JPATH_BASE.'/administrator/components/com_installer/component/component.class.php');
		require_once(JPATH_BASE.'/administrator/components/com_installer/module/module.class.php');
		require_once(JPATH_BASE.'/administrator/components/com_installer/mambot/mambot.class.php');
		$query = "SELECT id FROM #__components WHERE `option` = 'com_joomla_lms' AND parent = 0 AND iscore = 0";
		$database->SetQuery($query);
		$res = $database->LoadResult();
		$upload_dir_temp = '';
		if ($res) {
			$temp_folder_upload = md5(uniqid(rand(), true));
			$temp_path_upload = dirname(__FILE__). "/media/".$temp_folder_upload;
			if (mkdir($temp_path_upload)) {
				$upload_dir_temp = $temp_folder_upload;
				jh_copyUploadDirr(dirname(__FILE__)."/components/com_joomla_lms/upload", $temp_path_upload);
			}
			$installer = new mosInstallerComponent();
			$result = false;
			$result = $installer->uninstall( $res,'com_installer');
			$msg = $installer->getError();
			if ($result) {
				echo "<div class='jlms_test_ok'><span class='jlms_txt_ok'>Installer</span><br />".($msg?$msg:'Previous version has been successfully removed.')."</div>";
			} else {
				echo "<div class='jlms_test_error'><span class='jlms_txt_error'>Installer</span><br />".($msg?$msg:'An error occurred during uninstallation of the previous version.')."</div>";
			}
		}
		$zip_file = LH_SearchForFile(dirname(__FILE__));
		$next = true;
		if ($zip_file) {
			$paths = LH_PreparePackage($zip_file, 'media');
			$install_path = isset($paths['install_path']) ? $paths['install_path'] : '';
			$error_log = isset($paths['error_log']) ? $paths['error_log'] : '';
			$menu_module = isset($paths['menu_module']) ? $paths['menu_module'] : '';
			$search_bot = isset($paths['search_bot']) ? $paths['search_bot'] : '';
			$search_bot_new = isset($paths['search_bot_new']) ? $paths['search_bot_new'] : '';
			$cb_plugin_old = isset($paths['cb_plugin_old']) ? $paths['cb_plugin_old'] : '';
			$cb_plugin_new = isset($paths['cb_plugin_new']) ? $paths['cb_plugin_new'] : '';

			if ($error_log) {
				echo "<div class='jlms_test_error'><span class='jlms_txt_error'>Errors occurres during the installation:</span><br />".$error_log."</div>";
			}
			jh_KeepDB();
			if ($install_path) {
				if (!file_exists($install_path."/index.html")) {
					if (file_exists(dirname(__FILE__)."/components/index.html")) {
						@copy(dirname(__FILE__)."/components/index.html", $install_path."/index.html");
					}
				}
				$installer = new mosInstallerComponent();
				$path = mosPathName( $install_path );
				if (!is_dir( $path )) {
					$path = dirname( $path );
				}
				@ob_start();
				echo '---';
				$result = $installer->install( $path );
				@ob_end_clean();
				$add_notes = '';
				if ($result) {
					jh_KeepDB();

					/* LMS menu module */
					if ($menu_module) {
						$query = "SELECT count(id) FROM #__modules WHERE module = 'mod_jlms_menu'";
						$database->SetQuery( $query );
						$mod = $database->LoadResult();
						if (!$mod) {
							$minstaller = new mosInstallerModule();
							$path = mosPathName( $menu_module );
							if (!is_dir( $path )) {
								$path = dirname( $path );
							}
							@ob_start();
							echo '---';
							$result = $minstaller->install( $path );
							@ob_end_clean();
							if ($result) {
								$add_notes .= '<br />JoomlaLMS menu module has been successfully installed. You can publish it later.';
							} else {
								$add_notes .= '<br />JoomlaLMS menu module was NOT installed.';
							}
						} else {
							if (is_writable(dirname(__FILE__). "/modules/mod_jlms_menu.php") && is_writable(dirname(__FILE__). "/modules/mod_jlms_menu.xml")) {
								@copy($menu_module."/mod_jlms_menu.php", dirname(__FILE__). "/modules/mod_jlms_menu.php");
								@copy($menu_module."/mod_jlms_menu.xml", dirname(__FILE__). "/modules/mod_jlms_menu.xml");
								$add_notes .= '<br />JoomlaLMS menu module has been successfully updated.';
							} else {
								$add_notes .= '<br />JoomlaLMS menu module was not updated. Files are not writable.';
							}
						}
						jh_deldir($menu_module."/");
					}
					jh_KeepDB();

					/* LMS search bot */
					if ($search_bot) {
						$query = "SELECT count(id) FROM #__mambots WHERE folder = 'search' AND `element` = 'jlms.searchbot'";
						$database->SetQuery( $query );
						$bot = $database->LoadResult();
						if (!$bot) {
							$binstaller = new mosInstallerMambot();
							$path = mosPathName( $search_bot );
							if (!is_dir( $path )) {
								$path = dirname( $path );
							}
							@ob_start();
							echo '---';
							$result = $binstaller->install( $path );
							@ob_end_clean();
							if ($result) {
								$add_notes .= '<br />JoomlaLMS search mambot has been successfully installed. You can publish it later.';
							} else {
								$add_notes .= '<br />JoomlaLMS search mambot was NOT installed.';
							}
						} else {
							if (is_writable(dirname(__FILE__). "/mambots/search/jlms.searchbot.php") && is_writable(dirname(__FILE__). "/mambots/search/jlms.searchbot.xml")) {
								@copy($search_bot."/jlms.searchbot.php", dirname(__FILE__). "/mambots/search/jlms.searchbot.php");
								@copy($search_bot."/jlms.searchbot.xml", dirname(__FILE__). "/mambots/search/jlms.searchbot.xml");
								$add_notes .= '<br />JoomlaLMS search mambot has been successfully updated.';
							} else {
								$add_notes .= '<br />JoomlaLMS search mambot was NOT updated. Files are not writable.';
							}
						}
						jh_deldir($search_bot."/");
					}
					if ($search_bot_new) { jh_deldir($search_bot_new."/"); }
					jh_KeepDB();

					/* LMS CB plugins */
					if ($cb_plugin_old || $cb_plugin_new) {
						$ueConfig = array();
						if (file_exists(dirname(__FILE__). "/administrator/components/com_comprofiler/ue_config.php" )) {
							require_once(dirname(__FILE__). "/administrator/components/com_comprofiler/ue_config.php" );
						}
						$do_cb_plugin = '';
						if (isset($ueConfig['version']) && $ueConfig['version'] == '1.1' && $cb_plugin_new) {
							$do_cb_plugin = $cb_plugin_new;
						} elseif (isset($ueConfig['version']) && $ueConfig['version'] == '1.0.2' && $cb_plugin_old) {
							$do_cb_plugin = $cb_plugin_old;
						}
						if ($do_cb_plugin) {
							$query = "SELECT count(*) FROM #__comprofiler_plugin WHERE `element` = 'cb.joomlalms.autoenroll' AND type = 'user'";
							$database->SetQuery($query);
							$is_cb_i = $database->LoadResult();
							if ($is_cb_i) {
								if (is_writable(dirname(__FILE__). "/components/com_comprofiler/plugin/user/plug_joomlalmsautoenroll/cb.joomlalms.autoenroll.php") && is_writable(dirname(__FILE__). "/components/com_comprofiler/plugin/user/plug_joomlalmsautoenroll/cb.joomlalms.autoenroll.xml")) {
									@copy($do_cb_plugin."/cb.joomlalms.autoenroll.php", dirname(__FILE__). "/components/com_comprofiler/plugin/user/plug_joomlalmsautoenroll/cb.joomlalms.autoenroll.php");
									@copy($do_cb_plugin."/cb.joomlalms.autoenroll.xml", dirname(__FILE__). "/components/com_comprofiler/plugin/user/plug_joomlalmsautoenroll/cb.joomlalms.autoenroll.xml");
									@copy($do_cb_plugin."/index.html", dirname(__FILE__). "/components/com_comprofiler/plugin/user/plug_joomlalmsautoenroll/index.html");
									$add_notes .= '<br />JoomlaLMS CB autoenrollment plugin has been successfully updated.';
								} else {
									$add_notes .= '<br />JoomlaLMS CB autoenrollment plugin was NOT updated. Files are not writable.';
								}
							} else {
								@mkdir(dirname(__FILE__). "/components/com_comprofiler/plugin/user/plug_joomlalmsautoenroll");
								if (file_exists(dirname(__FILE__). "/components/com_comprofiler/plugin/user/plug_joomlalmsautoenroll")) {
									@copy($do_cb_plugin."/cb.joomlalms.autoenroll.php", dirname(__FILE__). "/components/com_comprofiler/plugin/user/plug_joomlalmsautoenroll/cb.joomlalms.autoenroll.php");
									@copy($do_cb_plugin."/cb.joomlalms.autoenroll.xml", dirname(__FILE__). "/components/com_comprofiler/plugin/user/plug_joomlalmsautoenroll/cb.joomlalms.autoenroll.xml");
									@copy($do_cb_plugin."/index.html", dirname(__FILE__). "/components/com_comprofiler/plugin/user/plug_joomlalmsautoenroll/index.html");
									$query = "INSERT INTO #__comprofiler_plugin (name, element, type, folder, access, ordering, published, iscore, client_id)"
									. "\n" . "VALUES ('JoomlaLMS AutoEnroll', 'cb.joomlalms.autoenroll', 'user', 'plug_joomlalmsautoenroll', 0, 0, 0, 0, 0)";
									$database->SetQuery($query);
									$database->query();
									$add_notes .= '<br />JoomlaLMS CB autoenrollment plugin has been successfully installed. You can publish it later.';
								} else {
									$add_notes .= '<br />JoomlaLMS CB autoenrollment plugin was NOT installed.';
								}
							}
						}
						if ($cb_plugin_old) { jh_deldir($cb_plugin_old."/"); }
						if ($cb_plugin_new) { jh_deldir($cb_plugin_new."/"); }
					}


					if ($upload_dir_temp) {
						$temp_path_upload = dirname(__FILE__). "/media/".$upload_dir_temp;
						jh_copyUploadDirr($temp_path_upload, dirname(__FILE__)."/components/com_joomla_lms/upload");
						jh_deldir($temp_path_upload."/");
					}
					echo "<div class='jlms_test_ok'><span class='jlms_txt_ok'>Installer</span><br />Trying to install $zip_file<br />New component has been successfully installed.".$add_notes."</div>";
				} else {
					echo "<div class='jlms_test_ok'><span class='jlms_txt_ok'>Installer</span><br />Trying to install $zip_file<br />An error occurred during the component's installation.".$add_notes."</div>";
				}
				jh_deldir($install_path."/");
			}
		}
	} else {
		jimport( 'joomla.application.component.model' );
		jimport( 'joomla.installer.installer' );
		//JPluginHelper::importPlugin('system');
		$installer =& JInstaller::getInstance();
		$query = "SELECT id FROM #__components WHERE `option` = 'com_joomla_lms' AND parent = 0 AND iscore = 0";
		$database->SetQuery($query);
		$res = $database->LoadResult();
		$upload_dir_temp = '';
		if ($res) {
			$temp_folder_upload = md5(uniqid(rand(), true));
			$temp_path_upload = dirname(__FILE__). "/tmp/".$temp_folder_upload;
			if (mkdir($temp_path_upload)) {
				$upload_dir_temp = $temp_folder_upload;
				jh_copyUploadDirr(dirname(__FILE__)."/components/com_joomla_lms/upload", $temp_path_upload);
			}
			$installer =& JInstaller::getInstance();
			$result = false;
			$result	= $installer->uninstall('component', $res );
			if ($result === false) {
				echo "<div class='jlms_test_error'><span class='jlms_txt_error'>Installer</span><br />An error occurred during uninstallation of the previous version.</div>";
			} else {
				echo "<div class='jlms_test_ok'><span class='jlms_txt_ok'>Installer</span><br />Previous version has been successfully removed.</div>";
			}
		}
		$zip_file = LH_SearchForFile(dirname(__FILE__));
		$next = true;
		if ($zip_file) {
			$paths = LH_PreparePackage($zip_file, 'tmp');
			$install_path = isset($paths['install_path']) ? $paths['install_path'] : '';
			$error_log = isset($paths['error_log']) ? $paths['error_log'] : '';
			$menu_module = isset($paths['menu_module']) ? $paths['menu_module'] : '';
			$search_bot = isset($paths['search_bot']) ? $paths['search_bot'] : '';
			$search_bot_new = isset($paths['search_bot_new']) ? $paths['search_bot_new'] : '';
			$cb_plugin_old = isset($paths['cb_plugin_old']) ? $paths['cb_plugin_old'] : '';
			$cb_plugin_new = isset($paths['cb_plugin_new']) ? $paths['cb_plugin_new'] : '';

			if ($error_log) {
				echo "<div class='jlms_test_error'><span class='jlms_txt_error'>Errors occurres during the installation:</span><br />".$error_log."</div>";
			}
			if ($install_path) {
				if (!file_exists($install_path."/index.html")) {
					if (file_exists(dirname(__FILE__)."/components/index.html")) {
						@copy(dirname(__FILE__)."/components/index.html", $install_path."/index.html");
					}
				}
				$installer = & JInstaller::getInstance();
				$path = JPath::clean( $install_path );

				if (!is_dir( $path )) {
					$path = dirname( $path );
				}
				@ob_start();
				echo '---';
				$result = $installer->install( $path );
				@ob_end_clean();
				$add_notes = '';
				if ($result) {
					jh_KeepDB();

					/* LMS menu module */
					if ($menu_module) {
						$query = "SELECT count(id) FROM #__modules WHERE module = 'mod_jlms_menu'";
						$database->SetQuery( $query );
						$mod = $database->LoadResult();
						if (!$mod) {
							$minstaller = & JInstaller::getInstance();
							$path = JPath::clean( $menu_module );
							if (!is_dir( $path )) {
								$path = dirname( $path );
							}
							@ob_start();
							echo '---';
							$result = $minstaller->install( $path );
							@ob_end_clean();
							if ($result) {
								$add_notes .= '<br />JoomlaLMS menu module has been successfully installed. You can publish it later.';
							} else {
								$add_notes .= '<br />JoomlaLMS menu module was NOT installed.';
							}
							if (!file_exists(dirname(__FILE__). "/modules/mod_jlms_menu/index.html")) {
								@copy(dirname(__FILE__)."/modules/index.html", dirname(__FILE__). "/modules/mod_jlms_menu/index.html");
							}
						} else {
							if (is_writable(dirname(__FILE__). "/modules/mod_jlms_menu/mod_jlms_menu.php") && is_writable(dirname(__FILE__). "/modules/mod_jlms_menu/mod_jlms_menu.xml")) {
								@copy($menu_module."/mod_jlms_menu.php", dirname(__FILE__). "/modules/mod_jlms_menu/mod_jlms_menu.php");
								@copy($menu_module."/mod_jlms_menu.xml", dirname(__FILE__). "/modules/mod_jlms_menu/mod_jlms_menu.xml");
								$add_notes .= '<br />JoomlaLMS menu module has been successfully updated.';
							} else {
								$add_notes .= '<br />JoomlaLMS menu module was not updated. Files are not writable.';
							}
						}
						jh_deldir($menu_module."/");
					}
					jh_KeepDB();

					/* LMS search bot */
					if ($search_bot_new) {
						$query = "SELECT count(id) FROM #__plugins WHERE folder = 'search' AND `element` = 'jlms_courses'";
						$database->SetQuery( $query );
						$bot = $database->LoadResult();
						if (!$bot) {
							$binstaller = & JInstaller::getInstance();
							$path = JPath::clean( $search_bot_new );
							if (!is_dir( $path )) {
								$path = dirname( $path );
							}
							@ob_start();
							echo '---';
							$result = $binstaller->install( $path );
							@ob_end_clean();
							if ($result) {
								$add_notes .= '<br />JoomlaLMS search plugin has been successfully installed. You could publish it later.';
							} else {
								$add_notes .= '<br />JoomlaLMS search plugin was NOT installed';
							}
						} else {
							if (is_writable(dirname(__FILE__). "/plugins/search/jlms_courses.php") && is_writable(dirname(__FILE__). "/plugins/search/jlms_courses.xml")) {
								@copy($search_bot_new."/jlms_courses.php", dirname(__FILE__). "/plugins/search/jlms_courses.php");
								@copy($search_bot_new."/jlms_courses.xml", dirname(__FILE__). "/plugins/search/jlms_courses.xml");
								$add_notes .= '<br />JoomlaLMS search plugin has been successfully updated.';
							} else {
								$add_notes .= '<br />JoomlaLMS search plugin was not updated. Files are not writable.';
							}
						}
						jh_deldir($search_bot_new."/");
					}
					if ($search_bot) { jh_deldir($search_bot."/"); }
					jh_KeepDB();

					/* LMS CB plugins */
					if ($cb_plugin_old || $cb_plugin_new) {
						$ueConfig = array();
						if (file_exists(dirname(__FILE__). "/administrator/components/com_comprofiler/ue_config.php" )) {
							require_once(dirname(__FILE__). "/administrator/components/com_comprofiler/ue_config.php" );
						}
						$do_cb_plugin = '';
						if (isset($ueConfig['version']) && $ueConfig['version'] == '1.1' && $cb_plugin_new) {
							$do_cb_plugin = $cb_plugin_new;
						} elseif (isset($ueConfig['version']) && $ueConfig['version'] == '1.0.2' && $cb_plugin_old) {
							$do_cb_plugin = $cb_plugin_old;
						}
						if ($do_cb_plugin) {
							$query = "SELECT count(*) FROM #__comprofiler_plugin WHERE `element` = 'cb.joomlalms.autoenroll' AND type = 'user'";
							$database->SetQuery($query);
							$is_cb_i = $database->LoadResult();
							if ($is_cb_i) {
								if (is_writable(dirname(__FILE__). "/components/com_comprofiler/plugin/user/plug_joomlalmsautoenroll/cb.joomlalms.autoenroll.php") && is_writable(dirname(__FILE__). "/components/com_comprofiler/plugin/user/plug_joomlalmsautoenroll/cb.joomlalms.autoenroll.xml")) {
									@copy($do_cb_plugin."/cb.joomlalms.autoenroll.php", dirname(__FILE__). "/components/com_comprofiler/plugin/user/plug_joomlalmsautoenroll/cb.joomlalms.autoenroll.php");
									@copy($do_cb_plugin."/cb.joomlalms.autoenroll.xml", dirname(__FILE__). "/components/com_comprofiler/plugin/user/plug_joomlalmsautoenroll/cb.joomlalms.autoenroll.xml");
									@copy($do_cb_plugin."/index.html", dirname(__FILE__). "/components/com_comprofiler/plugin/user/plug_joomlalmsautoenroll/index.html");
									$add_notes .= '<br />JoomlaLMS CB autoenrollment plugin has been successfully updated.';
								} else {
									$add_notes .= '<br />JoomlaLMS CB autoenrollment plugin was NOT updated. Files are not writable.';
								}
							} else {
								@mkdir(dirname(__FILE__). "/components/com_comprofiler/plugin/user/plug_joomlalmsautoenroll");
								if (file_exists(dirname(__FILE__). "/components/com_comprofiler/plugin/user/plug_joomlalmsautoenroll")) {
									@copy($do_cb_plugin."/cb.joomlalms.autoenroll.php", dirname(__FILE__). "/components/com_comprofiler/plugin/user/plug_joomlalmsautoenroll/cb.joomlalms.autoenroll.php");
									@copy($do_cb_plugin."/cb.joomlalms.autoenroll.xml", dirname(__FILE__). "/components/com_comprofiler/plugin/user/plug_joomlalmsautoenroll/cb.joomlalms.autoenroll.xml");
									@copy($do_cb_plugin."/index.html", dirname(__FILE__). "/components/com_comprofiler/plugin/user/plug_joomlalmsautoenroll/index.html");
									$query = "INSERT INTO #__comprofiler_plugin (name, element, type, folder, access, ordering, published, iscore, client_id)"
									. "\n" . "VALUES ('JoomlaLMS AutoEnroll', 'cb.joomlalms.autoenroll', 'user', 'plug_joomlalmsautoenroll', 0, 0, 0, 0, 0)";
									$database->SetQuery($query);
									$database->query();
									$add_notes .= '<br />JoomlaLMS CB autoenrollment plugin has been successfully installed. You can publish it later.';
								} else {
									$add_notes .= '<br />JoomlaLMS CB autoenrollment plugin was NOT installed.';
								}
							}
						}
						if ($cb_plugin_old) { jh_deldir($cb_plugin_old."/"); }
						if ($cb_plugin_new) { jh_deldir($cb_plugin_new."/"); }
					}

					if ($upload_dir_temp) {
						$temp_path_upload = dirname(__FILE__). "/tmp/".$upload_dir_temp;
						jh_copyUploadDirr($temp_path_upload, dirname(__FILE__)."/components/com_joomla_lms/upload");
						jh_deldir($temp_path_upload."/");
					}
					echo "<div class='jlms_test_ok'><span class='jlms_txt_ok'>Installer</span><br />Trying to install $zip_file<br />New component has been successfully installed.".$add_notes."</div>";
				} else {
					echo "<div class='jlms_test_ok'><span class='jlms_txt_ok'>Installer</span><br />Trying to install $zip_file<br />An error occurred during the component's installation.".$add_notes."</div>";
				}
				jh_deldir($install_path."/");
			}
		}
	}

	echo "<div class='jlms_simple'>";
	LH_ShowPrevBtn('joomlalms_helper.php?step=preinstall');
	echo "<br /></div>";
	LH_ShowEnd();
}

function LH_PreInstallCheck() {
	global $joomla_old;
	LH_ShowBegin();
	if ($joomla_old) {
		global $database;
	} else {
		$database = & JFactory::getDBO();
		$query = "SELECT published FROM #__plugins WHERE element = 'legacy' AND folder = 'system'";
		$database->SetQuery($query);
		$leg = $database->LoadResult();
		if ($leg) {
			echo "<div class='jlms_test_ok'><span class='jlms_txt_ok'>Joomla 1.5 legacy mode</span><br />Joomla 1.5 Legacy mode is enabled.</div>";
		} else {
			$query = "UPDATE #__plugins SET published = 1 WHERE element = 'legacy' AND folder = 'system'";
			$database->SetQuery($query);
			if ($database->query()) {
				echo "<div class='jlms_test_ok'><span class='jlms_txt_ok'>Joomla 1.5 legacy mode</span><br />Joomla 1.5 Legacy mode was automatically enabled.</div>";
			} else {
				echo "<div class='jlms_test_error'><span class='jlms_txt_error'>Joomla 1.5 legacy mode</span><br />Unable to publish Legacy mode plugin.</div>";
				echo "<div class='jlms_test_notice'><b>Instructions:</b> Try to enable Joomla 1.5 Legacy mode manually. Go to 'Extensions' menu -> 'Plugin manager' and publish 'System - Legacy' plugin.</div>";
			}
		}
	}
	$query = "SELECT count(*) FROM #__components WHERE `option` = 'com_joomla_lms'";
	$database->SetQuery($query);
	$res = $database->LoadResult();
	if ($res) {
		$database->SetQuery("SELECT lms_config_value FROM #__lms_config WHERE lms_config_var = 'jlms_version'");
		$prev_version = $database->LoadResult();
		if ($prev_version) {
			echo "<div class='jlms_test_warning'><span class='jlms_txt_warning'>Checking for previous version</span><br />JoomlaLMS version $prev_version is installed. Do you want to proceed with the installation?<br />The current installation will be removed (all database information will be kept) and a new one will be installed.</div>";
		} else {
			echo "<div class='jlms_test_warning'><span class='jlms_txt_warning'>Checking for previous version</span><br />DB entries of another JoomlaLMS installation are found, but it seems that it was corrupted. You should proceed the installation.<br />The current installation will be removed (all database information will be kept) and a new one will be installed.</div>";
		}
	}
	$zip_file = LH_SearchForFile(dirname(__FILE__));
	$next = true;
	if ($zip_file) {
		echo "<div class='jlms_test_ok'><span class='jlms_txt_ok'>JoomlaLMS package</span><br />The installation package was found: <b>$zip_file</b></div>";
	} else {
		$next = false;
		echo "<div class='jlms_test_error'><span class='jlms_txt_error'>JoomlaLMS package</span><br />The installation package wasn't found. <b>Please upload JoomlaLMS package into the Joomla! CMS root folder.</b></div>";		
	}
	if ($joomla_old) {
		$wr_folder = dirname(__FILE__). "/media";
	} else {
		$wr_folder = dirname(__FILE__). "/tmp";
	}
	if (is_writeable($wr_folder)) {
	} else {
		$next = false;
		echo "<div class='jlms_test_error'><span class='jlms_txt_error'>Temporary folder</span><br />Joomla! temporary folder (".($joomla_old?'media':'tmp').") is not writable. <b>Please check permissions and try again.</b></div>";
	}
	if ($next) {
		echo "<div class='jlms_simple'>";
		LH_ShowPrevBtn('joomlalms_helper.php');
		LH_ShowNextBtn('joomlalms_helper.php?step=install');
		echo "<br /></div>";
	} else {
		echo "<br /><div class='jlms_test_notice' style='text-align:center'><span class='jlms_txt_error'>Installation process was stopped.</span></div>";		
	}
	LH_ShowEnd();
}

function LH_GetCSS() {?>
html {
  height: 100%;
}
body {
	color:#333333;
	font-family:Helvetica,Arial,sans-serif;
	font-size:12px;
	line-height:1.3em;
	text-align:center;
}
div.nav_link a {
	font-size:12px;
}
a:hover {
	color:#0B3768;
}
a:link, a:visited {
	color:#135CAE;
}
div.center {
	text-align:center;
}
#page_bg {
	background:#F7F7F7 none repeat scroll 0%;
}
#whitebox {
	background:#FFFFFF none repeat scroll 0%;
	width:750px;
	margin:auto;
}
#whitebox div {
	text-align:left;
}
#whitebox_tr {
	background:transparent url(joomlalms_helper.php?step=image_tr) no-repeat scroll 100% 0pt;
	height:13px;
	overflow:hidden;
}
#whitebox_t {
	background:#FFFFFF url(joomlalms_helper.php?step=image_t) repeat-x left top;
}
#whitebox_tl {
	background:transparent url(joomlalms_helper.php?step=image_tl) no-repeat scroll 0pt;
}
#whitebox_m {
	border-left:1px solid #CCCCCC;
	border-right:1px solid #CCCCCC;
	width:auto;
	/*padding: 0px 7px;-right:7px;*/
}
#area {
	margin:0px 10px 0px 10px;
}
.clr {
	clear:both;
}
#whitebox_b {
	background:transparent url(joomlalms_helper.php?step=image_b) repeat-x scroll 0pt 100%;
}
#whitebox_bl {
	background:transparent url(joomlalms_helper.php?step=image_br) no-repeat scroll 100% 0pt;
}
#whitebox_br {
	background:transparent url(joomlalms_helper.php?step=image_bl) no-repeat scroll 0pt;
	height:13px;
}
#whitebox div {
	text-align:left;
}
#inst_footer {
	background:#F7F7F7 none repeat scroll 0%;
}
#inst_footer div {
	background:#F7F7F7 none repeat scroll 0%;
	text-align:right;
	font-size:10px;
	padding-right: 10px;
	padding-left: 10px;
}
#inst_tip div {
	text-align:left;
	font-size:10px;
	padding-right: 10px;
	padding-left: 10px;
	font-style:italic;
}
div.jlms_test_ok {
	border: 1px solid #BBDDBB;
	background-color: #DDFFDD;
	margin-bottom:3px;
	padding:3px;
	background: #DDFFDD url(joomlalms_helper.php?step=image_tick) right no-repeat;
}
div.jlms_simple {
	padding:3px;
}
div.jlms_test_notice {
	border: 1px solid #DDDDBB;
	background-color: #FFFFDD;
	margin-bottom:3px;
	padding:3px;
}
div.jlms_test_error {
	border: 1px solid #DDBBBB;
	background-color: #FFDDDD;
	margin-bottom:3px;
	padding:3px;
	background: #FFDDDD url(joomlalms_helper.php?step=image_error) right no-repeat;
}
div.jlms_test_warning {
	border: 1px solid #DDDDBB;
	background-color: #FFFFDD;
	margin-bottom:3px;
	padding:3px;
	background: #FFFFDD url(joomlalms_helper.php?step=image_warning) right no-repeat;
}
span.jlms_txt_ok {
	color:green;
	font-weight:bold;
}
span.jlms_txt_error {
	color:red;
	font-weight:bold;
}
span.jlms_txt_warning {
	color:orange;
	font-weight:bold;
}
<?php
}

function LH_ShowImage($image) {
	header('Content-type: image/png');
	switch ($image){
		case 'image_tr':
			echo base64_decode("iVBORw0KGgoAAAANSUhEUgAAAA0AAAANCAIAAAD9iXMrAAAAA3NCSVQICAjb4U/gAAAACXBIWXMAAAsSAAALEgHS3X78AAAAH3RFWHRTb2Z0d2FyZQBNYWNyb21lZGlhIEZpcmV3b3JrcyA4tWjSeAAAABZ0RVh0Q3JlYXRpb24gVGltZQAwNC8yNi8wNcVTO0AAAACsSURBVCiRhdA7CoQwFEbhPxIkIrfwAWKh4P63kk2IhVioYFIoBq+FM4MD4+TUX3WE1hrviEgplaaplBLfCWYGwMz7vhtj5nm21hJRURR3/XL3tm3r+35Zlqqqoih6dFfjOLZt2zTNRYOfCECWZXVdd13nnPvnAOR5TkTDMHgcgLIsjTHOOY9TSsVxPE2TxwFIkmRdV78jImut34VhCCB4+vdJCAEgOI6Dmb36BJoQTjhe4QLZAAAAAElFTkSuQmCC");
		break;
		case 'image_tl':
			echo base64_decode("iVBORw0KGgoAAAANSUhEUgAAAA0AAAANCAIAAAD9iXMrAAAAA3NCSVQICAjb4U/gAAAACXBIWXMAAAsSAAALEgHS3X78AAAAH3RFWHRTb2Z0d2FyZQBNYWNyb21lZGlhIEZpcmV3b3JrcyA4tWjSeAAAABZ0RVh0Q3JlYXRpb24gVGltZQAwNC8yNi8wNcVTO0AAAACfSURBVCiRjdGxDoQgEATQQQk0QoAGS/3/j7KgoqFZEii2uMLk7rx46rT7kplkRWsNxzBzKaX3TkQAhBAAxLdj5pxzrdUY47231o7juJ8+rrWWUnLOxRi11j8l8o22bVuWJYSAs8i9LqW0rqv3/hQBGADknJ1zFwjAwMxENM/zBQIwlFKmaVJK3bje+7/tB0dExph7B0BK+cjtn7l3T/IChItCKKPq+94AAAAASUVORK5CYII=");
		break;
		case 'image_t':
			echo base64_decode("iVBORw0KGgoAAAANSUhEUgAAACgAAAAICAIAAAAEMCoMAAAAA3NCSVQICAjb4U/gAAAACXBIWXMAAAsSAAALEgHS3X78AAAAH3RFWHRTb2Z0d2FyZQBNYWNyb21lZGlhIEZpcmV3b3JrcyA4tWjSeAAAABZ0RVh0Q3JlYXRpb24gVGltZQAwNC8yNi8wNcVTO0AAAAAhSURBVCiRYzx79izDQADG////D4jFTANi66jFoxbTEgAADZkFc6aJHYEAAAAASUVORK5CYII=");
		break;
		case 'image_b':
			echo base64_decode("iVBORw0KGgoAAAANSUhEUgAAADQAAAAKCAIAAAB0auphAAAAA3NCSVQICAjb4U/gAAAACXBIWXMAAAsSAAALEgHS3X78AAAAH3RFWHRTb2Z0d2FyZQBNYWNyb21lZGlhIEZpcmV3b3JrcyA4tWjSeAAAABZ0RVh0Q3JlYXRpb24gVGltZQAwNC8yNi8wNcVTO0AAAAAuSURBVDiNY/z//z/DYAVMA+0AfGDUceSCUceRC0YdRy4Y1I5jOXv27EC7AScAAAfZBXra92rUAAAAAElFTkSuQmCC");
		break;
		case 'image_br':
			echo base64_decode("iVBORw0KGgoAAAANSUhEUgAAAA0AAAANCAIAAAD9iXMrAAAAA3NCSVQICAjb4U/gAAAACXBIWXMAAAsSAAALEgHS3X78AAAAH3RFWHRTb2Z0d2FyZQBNYWNyb21lZGlhIEZpcmV3b3JrcyA4tWjSeAAAABZ0RVh0Q3JlYXRpb24gVGltZQAwNC8yNi8wNcVTO0AAAACcSURBVCiRjdExCsQgEAVQs1goRAQbO+9/GMktIoLNqCFqIDGFYVlY0PxuhseHYaZaKxplWZbPELWM3XVdr1zO+ZULIczzPHYAQAgZuJRSzlkI0XO1VmMMYwxj3HPW2m3bpJSoc4dzzlqrlMIYI4Sm/3+UUtZ1jTEqpSilbfm48zyP4/DeA8C+75xzKWVrepzW+jswxgghQohf0XID8c5JjrbW/XwAAAAASUVORK5CYII=");
		break;
		case 'image_bl':
			echo base64_decode("iVBORw0KGgoAAAANSUhEUgAAAA0AAAANCAIAAAD9iXMrAAAAA3NCSVQICAjb4U/gAAAACXBIWXMAAAsSAAALEgHS3X78AAAAH3RFWHRTb2Z0d2FyZQBNYWNyb21lZGlhIEZpcmV3b3JrcyA4tWjSeAAAABZ0RVh0Q3JlYXRpb24gVGltZQAwNC8yNi8wNcVTO0AAAACWSURBVCiRlc07CsQgGATgf0VQgg+wsgi5/2E8hVYiWKigYIhbBFIsuzE71TB8MGCMGQ+C4Fn+cb33ueOcp5TmjlIaY5w7pVQpZXqNMMacc+fcGOPOAYDWOud8/44AAGO8bZtzLoRwHMdX96q1nq3Waq1ljK3rSg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udc7zmlZxgBiTUeSM5XkgbjBB3gw5eNkNHMOFxuFKUIYI/tQUXL9eIYG+neDMD6rcVqdPpXUXtoH55+QkODtcon466amhpSRT0a3m1E+dFKZO9/ElqtDmfOnoVzanzH4eI2ismQRiKphX+ZxbzfT6ZOgrtuES6395TSLX08AFLOpEnvEtWNQT5tDHabXre0XERBfh68njmkpmqgz8xCx80u1NS9hfwDhdirTUdubh7IScNPiQg/DWQM034WRn0KgsEwliiUTIRv2S3aj3Td5+WcyhkK0jRT3ajs4XhNt/BiYWEBZrMZ6uRU+H1e/rtwKMS9CZCnVeB08/uor68ncI9hrXCQ0zbTKBi0D62A4yrXMlFoGQgGkMhI/vYVQiGjzN2jJDPO4krvJD98mztLHh3l5eW0Y6JURi+qq6vR1NSIwsLCLYwQbEwrZ+K4U3Ct/KZ3gv9dLZVg2rfAA6gtN3FLXbdubDJPHS+1XLHYnv359gQuZqjQaCrk0XPXxMQkBgcHdxYSfiiFG6DjxYtCRgmb27ph7p9C2l4VGHYFHvsU3q7KQWVJ3ijdZPqHDpCD7HzxwldHOsZYHCnQ4bMaE/J0kocmjodwY2C5k0uIgvMrYbz0yU/osc0iI10NVXQB1oERfPDm847Whlc2km+nhAM/Wn6T1l0yGwLBBDxzQIvXiktRkpmIsv0SnvuCNWFYB8BRMkHEcK9o6LPP4NTXXegbdiFJLUOBRoLh/jsQxqL49fPTwwdz9lGvof0vu+Buz5Bd2vBFe+7vXmIFDa9KpYc6yUBDQ1KWH4BaxsIVWIbV6YfNOY/QUhhiWp06pRiKsA/We0M4bNCj7XzTSHa6hitl5qNuw1tu37yszdxTYh5yYtxzH54VOR1YSw7JBSbqhmg1AgWhzEiRouF4xUjlYWMkRSHlbFPZ/92GO11uiimKJP41BciiSHgUe/8XWbZu9IAUQX4AAAAASUVORK5CYII=");
		break;
	}
	die;
}

function LH_MainPage() {
	LH_ShowBegin();
	echo 'JoomlaLMS requirements:<br /><br />';
	$status = true;
	$result1 = LH_TestJoomla();
	$status = $status && $result1['result'];
	LH_ShowBlockResults($result1);

	$result1 = LH_TestIoncube();
	$status = $status && $result1['result'];
	LH_ShowBlockResults($result1);
	echo '<br />Recommended PHP settings for proper work of all JoomlaLMS functions:<br /><br />';
	$result1 = LH_TestGD();
	$status = $status && (true || $result1['result']);
	LH_ShowBlockResults($result1);
	$result1 = LH_TestMEMLIMIT();
	$status = $status && (true || $result1['result']);
	LH_ShowBlockResults($result1);
	$result1 = LH_TestFileUploads();
	$status = $status && (true || $result1['result']);
	LH_ShowBlockResults($result1);
	echo '<br />Recommended PHP security settings:<br /><br />';
	$result1 = LH_TestMQGPC();
	$status = $status && (true || $result1['result']);
	LH_ShowBlockResults($result1);
	$result1 = LH_TestRG();
	$status = $status && (true || $result1['result']);
	LH_ShowBlockResults($result1);
	if ($status) {
		echo "<div class='jlms_simple'>";
		LH_ShowNextBtn('joomlalms_helper.php?step=preinstall');
		echo "<br /></div>";
	} else {
		echo "<br /><div class='jlms_test_notice' style='text-align:center'><span class='jlms_txt_error'>Pre-installation test has failed.</span></div>";
	}
	LH_ShowEnd();
}

function LH_ShowBlockResults(&$result) {
	echo '<div class="jlms_test_'.$result['class'].'"><span class="jlms_txt_'.$result['class'].'">'.$result['caption'].'</span>'.($result['text'] ? ('<br />'.$result['text']) : '').'</div>';
	if (!empty($result['instructions'])) {
		echo '<div class="jlms_test_notice"><b>Instructions: </b>'.$result['instructions'].'</div>';
	}
}

function LH_ShowBegin() {
	echo '<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
	<title>JoomlaLMS installation</title>
	<link href="joomlalms_helper.php?step=getcss" rel="stylesheet" type="text/css" />
	</head>';
	echo '<body id="page_bg"><br /><br /><br /><div style="width:100%; text-align:center">';
					echo '<div id="whitebox">';
						echo '<div id="whitebox_t">
								<div id="whitebox_tl">
									<div id="whitebox_tr"><!--x--></div>
								</div>
							</div>';
						echo '<div id="whitebox_m">';
							echo '<div id="area">';
}

function LH_ShowEnd() {
	echo '<br /><div id="inst_tip"><div>Remember to remove this script after JoomlaLMS installation.</div></div>';
	echo '</div>';
							echo '<div class="clr"></div>';
						echo '</div>';
						echo '<div id="whitebox_b">
								<div id="whitebox_bl">
									<div id="whitebox_br"><!--x--></div>
								</div>
							</div>';
						echo '<div id="inst_footer"><div style="float:left">Copyright &copy; 2007 by <a href="http://www.elearningforce.biz" target="_blank">Elearningforce Inc.</a></div><div style="float:right">JoomlaLMS Installation Helper 1.1. Powered by <a href="http://www.joomlalms.com" target="_blank">www.joomlalms.com</a></div><br /></div>';
					echo '</div>';
		echo '</div>';
	echo '</body>';
	echo '</html>';
}

function LH_ShowNextBtn($link) {
	echo '<div style="float:right;"><table cellpadding="0" cellspacing="0" border="0"><tr><td valign="middle"><div class="nav_link"><a href="'.$link.'">NEXT</a>&nbsp;</div></td><td>';
	echo '<a href="'.$link.'"><img src="joomlalms_helper.php?step=image_forward" width="32" height="32" border="0" /></a></td></tr></table></div>';
}

function LH_ShowPrevBtn($link) {
	echo '<div style="float:left"><table cellpadding="0" cellspacing="0" border="0"><tr><td><a href="'.$link.'"><img src="joomlalms_helper.php?step=image_back" width="32" height="32" border="0" /></a></td><td>';
	echo '<div class="nav_link">&nbsp;<a href="'.$link.'">BACK</a></div></td></tr></table></div>';
}

function LH_TestMQGPC() {
	$ret = array('result' => true, 'class' => 'warning', 'caption' => 'PHP magic_quotes_gpc setting', 'text' => '', 'instructions' => '');
	if (@ini_get('magic_quotes_gpc') != '1' ) {
		$ret['text'] = "PHP magic_quotes_gpc setting is 'OFF' instead of 'ON'";
		$ret['instructions'] = "Enabling this setting will improve the security of your site. If you are using not-trusted 3pd extensions which can be vulnerable to SQl-injections enable this setting. The SQL injections will still be possible, but the risk will be reduced.<br />\n";
		$ret['instructions'] .= "For more information please visit the <a target='_blank' href='http://help.joomla.org/component/option,com_easyfaq/task,view/id,167/Itemid,268/'>FAQ</a> page on the official <a target='_blank' href='http://help.joomla.org/component/option,com_easyfaq/task,cat/catid,226/Itemid,99999999/'>Joomla! Help Site</a>.";
	} else {
		$ret['class'] = 'ok';
		$ret['text'] = "PHP magic_quotes_gpc setting is 'ON'";
	}
	return $ret;
}

function LH_TestRG() {
	$ret = array('result' => true, 'class' => 'warning', 'caption' => 'PHP register_globals setting', 'text' => '', 'instructions' => '');
	if ( @ini_get('register_globals') == '1' ) {
		$ret['text'] = "PHP register_globals setting is 'ON' instead of 'OFF'";
	} else {
		$ret['class'] = 'ok';
		$ret['text'] = "PHP register_globals setting is 'OFF'";
	}
	return $ret;
}

function LH_TestMEMLIMIT() {
	$ret = array('result' => true, 'class' => 'warning', 'caption' => 'PHP Memory Limit', 'text' => '', 'instructions' => '');
	$a = @ini_get('memory_limit');
	if (!$a) {
		$a = get_cfg_var('memory_limit');
	}
	$ml = intval($a);
	$add_instructions = false;
	if ($ml > 0 && $ml < 9) {
		$ret['text'] = 'PHP Memory Limit is set to '.$ml.'M.';
		$add_instructions = true;
		$ret['instructions'] = "In order for all JoomlaLMS and Joomla functions to work properly you should extend this setting.<br />\n";
	} elseif ($ml > 0 && $ml < 15) {
		$ret['text'] = 'PHP Memory Limit is set to '.$ml.'M.';
		$add_instructions = true;
		$ret['instructions'] = "This is enough for working with standard Joomla installation.<br />\n";
	} elseif ($ml > 0) {
		$ret['class'] = 'ok';
		$ret['text'] = 'PHP Memory Limit is set to '.$ml.'M.';
	} else {
		$ret['class'] = 'ok';
		$ret['text'] = 'PHP Memory Limit setting is disabled.';
	}
	if ($add_instructions) {
		$ret['instructions'] .= "If you get the error <b>\"Fatal error: Allowed memory size of X bytes exhausted\"</b> you will need more memory.<br />\n";
		$ret['instructions'] .= "To increase this setting modify your php.ini, try this value first:<br />\n";
		$ret['instructions'] .= "&nbsp;&nbsp;&nbsp;memory_limit = 20M<br />\n";
		$ret['instructions'] .= "If you still get the error you will need more memory like:<br />\n";
		$ret['instructions'] .= "&nbsp;&nbsp;&nbsp;memory_limit = 40M<br />\n";
		$ret['instructions'] .= "If, however, you have set your limit to 40M and the fatal memory error does not show, you can try lowering it down like:<br />\n";
		$ret['instructions'] .= "&nbsp;&nbsp;&nbsp;memory_limit = 32M<br />\n";
		$ret['instructions'] .= "If you still don't get the error, try lowering the memory_limit further. The idea is to have the least amount of memory_limit specification possible as long as you don't get fatal memory errors.";
	}
	return $ret;
}

function LH_TestFileUploads() {
	$ret = array('result' => true, 'class' => 'warning', 'caption' => 'File Uploads', 'text' => '', 'instructions' => '');
	$a = intval(@ini_get('post_max_size'));
	$b = intval(@ini_get('upload_max_filesize'));
	$limit = 0;
	if ($a || $b) {
		$limit = ($a < $b) ? $a : $b;
		if (!$limit) {
			$limit = $b;
		}
	}
	$ret['text'] = 'PHP post_max_size setting is '.@ini_get('post_max_size').'<br />';
	$ret['text'] .= 'PHP upload_max_filesize setting is '.@ini_get('upload_max_filesize').'<br />';
	if ($limit && $limit < 5) {
		$ret['instructions'] = 'You could upload documents, SCORM packages or other learning materials with the size of no more than '.$limit.'Mb.<br />';
		$ret['instructions'] .= 'To enlarge the possible size of uploaded files you should increase post_max_size and upload_max_filesize PHP settings.<br />';
		$ret['instructions'] .= "Add the below to the relevant php.ini file (recommended, if you have access). Note that for some hosts this is a system-wide setting. However, for hosts running PHP as a CGI script with suexec (for example) you may be able to put these directives in the php.ini file in your Joomla root directory.<br />";
		$ret['instructions'] .= "&nbsp;&nbsp;&nbsp;upload_max_filesize = 10M ;<br />\n";
		$ret['instructions'] .= "&nbsp;&nbsp;&nbsp;post_max_size = 20M ;<br />\n";
		$ret['instructions'] .= "If you don't have the access to your php.ini file add the below to your .htaccess file in your Joomla root directory.<br />\n";
		$ret['instructions'] .= "&nbsp;&nbsp;&nbsp;php_value upload_max_filesize 10M<br />\n";
		$ret['instructions'] .= "&nbsp;&nbsp;&nbsp;php_value post_max_size 20M<br />\n";
	} else {
		$ret['class'] = 'ok';
	}
	return $ret;
}

function LH_TestGD() {
	$ret = array('result' => true, 'class' => 'warning', 'caption' => 'PHP GD-support', 'text' => '', 'instructions' => '');
	$add_install_instructions = true;
	if(function_exists("gd_info")) {
		$info = gd_info();
		$version = $info["GD Version"];
		if(strpos($version,'2.') !== false && function_exists('imagecreatetruecolor')) {
			$ret['class'] = 'ok';
			$ret['text'] = 'GD2 Library '.$version.' is installed.';
			$add_install_instructions = false;
		} else {
			$ret['text'] = 'GD Library '.$version.' is installed.';
		}
	} else {
		$ret['text'] = 'GD image library is not installed.';
	}
	if ($add_install_instructions) {
		$ret['instructions'] = "In order for all JoomlaLMS functions (such as printing certificates and graphical overview of the course tracking) to work properly you should install GD2 Library.<br />\n";
		$ret['instructions'] .= "To enable GD-support configure PHP --with-gd[=DIR], where DIR is the GD base install directory. To use the recommended bundled version of the GD library, use the configure option --with-gd. GD library requires libpng and libjpeg to compile.<br />\n";
		$ret['instructions'] .= "In Windows you'll include the GD2 DLL php_gd2.dll as an extension to php.ini.<br />\n";
	} else {
		if(function_exists("gd_info")) {
			$info = gd_info();
			if (empty($info["PNG Support"])) {
				$ret['class'] = 'warning';
				$ret['instructions'] .= "<br /><b>PNG support</b> should be enabled.<br />\n";
				$ret['instructions'] .= "To enable support for png add --with-png-dir=DIR to the PHP configure line. Note, libpng requires the zlib library, therefore add --with-zlib-dir[=DIR] to your configure line.<br />\n";
				$ret['instructions'] .= "Alternatively contact your hosting provider or system administrator and ask them to enable PHP GD PNG support.<br />\n";
			} else {
				$ret['text'] .= "<br />PNG support is enabled.";
			}
			if (empty($info["FreeType Support"])) {
				$ret['class'] = 'warning';
				$ret['instructions'] .= "<br /><b>FreeType Support</b> should be enabled.<br />\n";
				$ret['instructions'] .= "To enable support for FreeType 2 add --with-freetype-dir=DIR to the PHP configure line.<br />\n";
				$ret['instructions'] .= "Alternatively, contact your hosting provider or system administrator, and ask them to enable PHP GD FreeType support.<br />\n";
			} else {
				$ret['text'] .= "<br />FreeType support is enabled";
			}
		}
	}
	return $ret;
}

function LH_TestJoomla() {
	$ret = array('result' => false, 'class' => 'error', 'caption' => 'Joomla! CMS', 'text' => 'Joomla! CMS not found', 'instructions' => '');
	if (file_exists(dirname(__FILE__)."/includes/version.php")) {
		require_once(dirname(__FILE__)."/includes/version.php");
		if (!isset($_VERSION)) {
			global $_VERSION;
		}
		$result = $_VERSION->getShortVersion();
		$ret['result'] = true;
		$ret['caption'] = 'Joomla! CMS installed';
		$ret['class'] = 'ok';
		$ret['text'] = '<b>Version:</b> '.$result;
		if ($_VERSION->RELEASE == '1.0') {
			if (intval($_VERSION->DEV_LEVEL) < 12) {
				$ret['class'] = 'warning';
				$ret['instructions'] = "You MUST UPGRADE to higher version due to several High Level vulnerabilities that affect this version of Joomla!";
			}
		}
	} elseif(file_exists(dirname(__FILE__)."/libraries/joomla/version.php")) {
		require_once(dirname(__FILE__)."/libraries/joomla/version.php");
		$_VERSION = new JVersion();
		$result = $_VERSION->getShortVersion();
		$ret['result'] = true;
		$ret['caption'] = 'Joomla! CMS installed';
		$ret['text'] = '<b>Version:</b> '.$result;
		/* LEGACY CHECK */
		if (!defined('_JEXEC')) { define( '_JEXEC', 1 ); }
		if (!defined('JPATH_BASE')) { define('JPATH_BASE', dirname(__FILE__) ); }
		if (!defined('DS')) { define( 'DS', DIRECTORY_SEPARATOR ); }

		if (file_exists(JPATH_BASE.'/includes/joomla.php') && file_exists(JPATH_BASE.'/configuration.php') && file_exists(JPATH_BASE.'/libraries/loader.php')) {
			require_once( JPATH_BASE .DS.'includes'.DS.'defines.php' );
			require_once( JPATH_BASE .DS.'includes'.DS.'framework.php' );
			//require_once( JPATH_BASE .DS.'includes'.DS.'helper.php' );
	
			//JDEBUG ? $_PROFILER->mark( 'afterLoad' ) : null;
			if (class_exists('JApplication')) {
				$mainframe =& JApplication::getInstance('site');
			} else {
				$mainframe =& JFactory::getApplication('site');
			}
			JPluginHelper::importPlugin('system');

			$database = & JFactory::getDBO();
			$query = "SELECT published FROM #__plugins WHERE element = 'legacy' AND folder = 'system'";
			$database->SetQuery($query);
			$leg = $database->LoadResult();
			if ($leg) {
				$ret['class'] = 'ok';
				$ret['text'] .= '<br /><b>Legacy Mode:</b> On';
			} else {
				$ret['class'] = 'warning';
				$ret['text'] .= '<br /><b>Legacy Mode:</b> Off.';
				$ret['instructions'] = "JoomlaLMS requires enabled Legacy mode. You don't need to publish this plugin, it will be automatically published before the component's installation.";
			}
		} else {
			$ret['caption'] = 'Joomla! CMS has not been properly installed or there was an error while getting information about your CMS.';
			$ret['class'] = 'error';
			$ret['result'] = false;
			$ret['text'] .= '<br /><b>Legacy Mode:</b> Unable to get information about Legacy mode plugin. It seems that your Joomla! CMS has not been properly installed. The installation process might cause errors.';
		}
	} else {
		$ret['result'] = false;
		$ret['class'] = 'error';
		$ret['instructions'] = "Joomla! CMS was not found. Please make sure that Joomla is installed and this script is uploaded into the Joomla root folder";
	}
	return $ret;
}
function LH_TestIoncube() {
	$ret = array('result' => false, 'class' => 'error', 'caption' => 'ionCube Loader','text' => '', 'instructions' => '');
	
	if (extension_loaded('ionCube Loader') ) {
		$ioncube_loader_version = ioncube_loader_version();
		$ioncube_loader_version_major = substr($ioncube_loader_version,0,1);
		$ioncube_loader_version_minor = substr($ioncube_loader_version,2,1);
		if ($ioncube_loader_version_major < 3 || ($ioncube_loader_version_major == 3 && $ioncube_loader_version_minor < 1) ) {
			$ret['instructions'] = "Ioncube loader is installed but needs to be updated.<br />\n
			JoomlaLMS will only work with ioncube loader version 3.1 or later.<br />\n
			The most recent version of the loader can be found <a href=\"http://www.ioncube.com/loaders.php\" target=\"_blank\">here</a>.";
		} else {
			$ret['class'] = 'ok';
			$ret['result'] = true;
		}
		$ret['caption'] = 'ionCube Loader is installed';
		$ret['text'] = '<b>Version:</b> '.$ioncube_loader_version;
	} else {
		$ret['caption'] = 'ionCube Loader';
		$ret['text'] = 'ionCube Loader not installed';
		$ret['instructions'] = "Testing whether your system supports run-time loading...<br />\n";
		$sys_info = array();
		$sys_info = LH_SysInfo();
		$try_to_install = true;
		if (isset($sys_info['THREAD_SAFE']) && $sys_info['THREAD_SAFE'] && isset($sys_info['CGI_CLI']) && !$sys_info['CGI_CLI']) {
			$ret['instructions'] .= "<br />\nYour PHP install appears to have <b>threading support</b> and run-time Loading is only possible on <b>threaded web servers if using the CGI, FastCGI or CLI interface.</b><br />\n";
			$ret['instructions'] .= "To run encoded files please install the Loader into the <b>php.ini</b> file. Instructions can be found <a href=\"http://www.ioncube.com/loader_installation.php\" target=\"_blank\">here</a>.<br />\n";
			$try_to_install = false;
		}
		if (isset($sys_info['DEBUG_BUILD']) && $sys_info['DEBUG_BUILD']) {
			$ret['instructions'] .= "<br />\nYour PHP installation appears to be built with <b>enabled debugging support</b>.ionCube Loaders are incompatible with this option.<br />Debugging support in PHP produces slower execution, it's not recommended for production builds and was probably installed by a mistake.<br />\n";
			$ret['instructions'] .= "You should rebuild PHP without the --enable-debug option.<br />\n";
			$try_to_install = false;
		}
		if (@ini_get('safe_mode') ) {
			$ret['instructions'] .= "<br />\nPHP <b>safe mode is enabled</b> and run time loading will not be possible.<br />";
			$ret['instructions'] .= "To run encoded files please install the Loader into the <b>php.ini</b> file. Instructions can be found <a href=\"http://www.ioncube.com/loader_installation.php\" target=\"_blank\">here</a><br />\n";
			$ret['instructions'] .= "Alternatively contact your hosting provider or system administrator and ask them to disable safe mode for your account.<br />\n";
			$try_to_install = false;
		}


		if ($try_to_install) {
			/* Look for a Loader */
			$_u = php_uname();
			$_os = substr($_u,0,strpos($_u,' '));
			$_os_key = strtolower(substr($_u,0,3));

			$_php_version = phpversion();
			$_php_family = substr($_php_version,0,3);

			$_loader_sfix = (($_os_key == 'win') ? '.dll' : '.so');

			$_ln_old="ioncube_loader.$_loader_sfix";
			$_ln_old_loc="/ioncube/$_ln_old";

			$_ln_new="ioncube_loader_${_os_key}_${_php_family}${_loader_sfix}";
			$_ln_new_loc="/ioncube/$_ln_new";

			$ret['instructions'] .= "Looking for Loader '$_ln_new'<br />\n";

			$_extdir = @ini_get('extension_dir');
			if ($_extdir == './') { $_extdir = '.'; }

			$_oid = $_id = realpath($_extdir);

			$_here = dirname(__FILE__);
			if ((@$_id[1]) == ':') {
				$_id = str_replace('\\','/',substr($_id,2));
				$_here = str_replace('\\','/',substr($_here,2));
			}
			$_rd=str_repeat('/..',substr_count($_id,'/')).$_here.'/';
		
			if ($_oid !== false) {
				$ret['instructions'] .=  "Extensions Dir: $_extdir ($_id)<br />\n";
				$ret['instructions'] .=  "Relative Path:  $_rd<br />\n";
			} else {
				$ret['instructions'] .=  "Extensions Dir: $_extdir (NOT FOUND)<br />\n";
		
				$ret['instructions'] .= "The directory set for the <b>extension_dir</b> entry in the php.ini file <b>may not exist</b>, and run time loading will not be possible.<br />\n";
				$ret['instructions'] .= "Please ask your hosting provider or system administrator to create the directory<br />$_extdir<br />ensuring that it is accessible by the web server software. They do not need to restart the server. Then rerun this script.";
				$ret['instructions'] .= " As an alternative your host could install the Loader into the php.ini file. Instructions can be found <a href=\"http://www.ioncube.com/loader_installation.php\" target=\"_blank\">here</a>.<br />\n";
				$try_to_install = false;
			}

			if ($try_to_install) {
				$_ln = '';
				$_i=strlen($_rd);
				while($_i--) {
					if($_rd[$_i]=='/') {
						$_lp=substr($_rd,0,$_i).$_ln_new_loc;
						$_fqlp=$_oid.$_lp;
						if(@file_exists($_fqlp)) {
							$ret['instructions'] .= "Loader $_fqlp was found.<br />\n";
							$_ln=$_lp;
							break;
						}
					}
				}
				// If Loader not found, try the fallback of in the extensions directory
				if (!$_ln) {
					if (@file_exists($_id.$_ln_new_loc)) {
						$_ln = $_ln_new_loc;
					}
					if ($_ln) {
						$ret['instructions'] .= "Loader $_ln was found in the extensions directory.<br />\n";
					}
				}
				$ret['instructions'] .= "<br />\n";

				if ($_ln) {
					$ret['instructions'] .= "Trying to install the Loader - this may produce an error...<br />\n";
					@dl($_ln);
					if( extension_loaded('ionCube Loader') ) {
						$ret['class'] = 'ok';
						$ret['result'] = true;
						$ret['text'] = 'ionCube Loader has been successfully installed';
						$ret['instructions'] .= "The Loader has been successfully installed and encoded files should be able to automatically install the Loader when needed.<br />\n";
						$ret['instructions'] .= "No changes to your php.ini file are required in order to use encoded files on this system.";
					} else {
						$ret['instructions'] .= "Loader was not installed.";
					}
				} else {
					$ret['instructions'] .= "Run-time loading should be possible on your system but no suitable Loader was found.<br />\n";
					$ret['instructions'] .= "The Loader for <b>$_os</b> (PHP $_php_family) is required.<br />\n";
					$ret['instructions'] .= "Loaders can be downloaded from <a href=\"http://www.ioncube.com/loaders.php\" target=\"_blank\">www.ioncube.com</a><br />\n";
					$ret['instructions'] .= "Please download the appropriate loader, extract the package and upload the 'ioncube' folder into the root directory of your site (e.g. '/public_html/ioncube/' or '/htdocs/ioncube/'). <b>After that run this script again.</b>";
				}
			}
		}

		if (empty($ret['instructions'])) {
			$ret['instructions'] = "Run-time loading is not currently possible.<br />\n"."Please contact JoomlaLMS support providing a link to this script.";
		}
	}
	return $ret;
}


function LH_SysInfo() {
	$thread_safe = false;
	$debug_build = false;
	$cgi_cli = false;
	$php_ini_path = '';

	ob_start();
	phpinfo(INFO_GENERAL);
	$php_info = ob_get_contents();
	ob_end_clean();

	foreach (split("\n",$php_info) as $line) {
		if (eregi('command',$line)) {
			continue;
		}

		if (preg_match('/thread safety.*(enabled|yes)/Ui',$line)) {
			$thread_safe = true;
		}

		if (preg_match('/debug.*(enabled|yes)/Ui',$line)) {
			$debug_build = true;
		}

		if (eregi("configuration file.*(</B></td><TD ALIGN=\"left\">| => |v\">)([^ <]*)(.*</td.*)?",$line,$match)) {
			$php_ini_path = $match[2];
			if (!@file_exists($php_ini_path)) {
				$php_ini_path = '';
			}
		}

		$cgi_cli = ((strpos(php_sapi_name(),'cgi') !== false) || (strpos(php_sapi_name(),'cli') !== false));
	}

	return array('THREAD_SAFE' => $thread_safe, 'DEBUG_BUILD' => $debug_build, 'PHP_INI'     => $php_ini_path, 'CGI_CLI'     => $cgi_cli);
}

function LH_SearchForFile($dir) {
	$priority = 10;
	$zip_file = '';
	if ($current_dir = @opendir( $dir )) {
		//$old_umask = umask(0);
		while ($entryname = readdir( $current_dir )) {
			if ($entryname != '.' and $entryname != '..') {
				if (is_dir( $dir . "/".$entryname )) {
	
				} else {
					if (substr($entryname,-4) == '.zip') {
						if (strtolower(substr($entryname,5,11)) == '_joomlalms_' && strtolower(substr($entryname,21,13)) == '_pro_unzip1st' && $priority > 1) {
							$zip_file = $entryname; $priority = 1;
						}
						if (strtolower(substr($entryname,0,10)) == 'joomlalms_' && strtolower(substr($entryname,15,15)) == '_trial_unzip1st' && $priority > 2) {
							$zip_file = $entryname; $priority = 2;
						}
						if (strtolower($entryname) == 'com_joomla_lms.zip' && $priority > 3) {
							$zip_file = $entryname; $priority = 3;
						}
					}
				}
			}
		}
		closedir( $current_dir );
	} else {
		echo "Failed to open DIR $dir";
	}
	return $zip_file;
}

function LH_PreparePackage($zip_file, $jtf) {
	$paths = array();
	$paths['install_path'] = '';
	$paths['error_log'] = '';
	$paths['menu_module'] = '';
	$paths['search_bot'] = '';
	$paths['search_bot_new'] = '';
	$paths['cb_plugin_old'] = '';
	$paths['cb_plugin_new'] = '';
	if ($zip_file == 'com_joomla_lms.zip') {
		jh_extractBackupArchive(dirname(__FILE__)."/".$zip_file, dirname(__FILE__)."/".$jtf."/");
		$paths['install_path'] = dirname(__FILE__) ."/".$jtf."/com_joomla_lms";
		if (file_exists($paths['install_path']."/")) {
		} else {
			$paths['error_log'] .= "Unknown error at line ".__LINE__.".<br />";
		}
	} else {
		$temp_folder = md5(uniqid(rand(), true));
		$temp_path = dirname(__FILE__). "/".$jtf."/".$temp_folder;
		if (mkdir($temp_path)) {
			jh_extractBackupArchive(dirname(__FILE__)."/".$zip_file, $temp_path."/");
			if (file_exists($temp_path."/com_joomla_lms.zip")) {
				jh_extractBackupArchive($temp_path."/com_joomla_lms.zip", dirname(__FILE__)."/".$jtf."/");
				$paths['install_path'] = dirname(__FILE__) ."/".$jtf."/com_joomla_lms";
				if (file_exists($temp_path."/modules_plugins/mod_jlms_menu.zip")) {
					$do_extract = false;
					if (!file_exists(dirname(__FILE__)."/".$jtf."/mod_lms_menu/")) {
						if (mkdir(dirname(__FILE__)."/".$jtf."/mod_lms_menu/")) {
							$do_extract = true;
						}
					} else { $do_extract = true; }
					if ($do_extract) {
						jh_extractBackupArchive($temp_path."/modules_plugins/mod_jlms_menu.zip", dirname(__FILE__)."/".$jtf."/mod_lms_menu/");
						$paths['menu_module'] = dirname(__FILE__)."/".$jtf."/mod_lms_menu";
					}
				}
				if (file_exists($temp_path."/modules_plugins/jlms_searchbot.zip")) {
					$do_extract = false;
					if (!file_exists(dirname(__FILE__)."/".$jtf."/bot_lms_search/")) {
						if (mkdir(dirname(__FILE__)."/".$jtf."/bot_lms_search/")) {
							$do_extract = true;
						}
					} else { $do_extract = true; }
					if ($do_extract) {
						jh_extractBackupArchive($temp_path."/modules_plugins/jlms_searchbot.zip", dirname(__FILE__)."/".$jtf."/bot_lms_search/");
						$paths['search_bot'] = dirname(__FILE__)."/".$jtf."/bot_lms_search";
					}
				}
				if (file_exists($temp_path."/modules_plugins/jlms_searchplugin_1.5.zip")) {
					$do_extract = false;
					if (!file_exists(dirname(__FILE__)."/".$jtf."/bot_lms_search_new/")) {
						if (mkdir(dirname(__FILE__)."/".$jtf."/bot_lms_search_new/")) {
							$do_extract = true;
						}
					} else { $do_extract = true; }
					if ($do_extract) {
						jh_extractBackupArchive($temp_path."/modules_plugins/jlms_searchplugin_1.5.zip", dirname(__FILE__)."/".$jtf."/bot_lms_search_new/");
						$paths['search_bot_new'] = dirname(__FILE__)."/".$jtf."/bot_lms_search_new";
					}
				}
				if (file_exists($temp_path."/modules_plugins/cb_joomlalms_autoenroll.zip")) {
					$do_extract = false;
					if (!file_exists(dirname(__FILE__)."/".$jtf."/cb_lms_autoenroll_old/")) {
						if (mkdir(dirname(__FILE__)."/".$jtf."/cb_lms_autoenroll_old/")) {
							$do_extract = true;
						}
					} else { $do_extract = true; }
					if ($do_extract) {
						jh_extractBackupArchive($temp_path."/modules_plugins/cb_joomlalms_autoenroll.zip", dirname(__FILE__)."/".$jtf."/cb_lms_autoenroll_old/");
						$paths['cb_plugin_old'] = dirname(__FILE__)."/".$jtf."/cb_lms_autoenroll_old";
					}
				}
				if (file_exists($temp_path."/modules_plugins/cb_joomlalms_autoenroll_1.1.zip")) {
					$do_extract = false;
					if (!file_exists(dirname(__FILE__)."/".$jtf."/cb_lms_autoenroll_new/")) {
						if (mkdir(dirname(__FILE__)."/".$jtf."/cb_lms_autoenroll_new/")) {
							$do_extract = true;
						}
					} else { $do_extract = true; }
					if ($do_extract) {
						jh_extractBackupArchive($temp_path."/modules_plugins/cb_joomlalms_autoenroll_1.1.zip", dirname(__FILE__)."/".$jtf."/cb_lms_autoenroll_new/");
						$paths['cb_plugin_new'] = dirname(__FILE__)."/".$jtf."/cb_lms_autoenroll_new";
					}
				}
				if (file_exists($paths['install_path'])) {
				} else {
					$paths['error_log'] .= "Unknown error in line ".__LINE__.".<br />";
				}
			} else {
				$paths['error_log'] .= "Unable to unpack JoomlaLMS package.<br />";
			}
			sleep(1);
			jh_deldir($temp_path."/");
		} else {
			$paths['error_log'] .= "Function mkdir() failed in line ".__LINE__.".<br />";
		}
	}
	return $paths;
}
function jh_extractBackupArchive($archivename , $extractdir) {

	$archivename = mosPathName( $archivename, false );
	if (eregi( '.zip$', $archivename )) {
		// Extract functions

		$backupfile = new PclZip( $archivename );

		$ret = $backupfile->extract( PCLZIP_OPT_PATH, $extractdir );

	}
	return true;
}
function jh_deldir( $dir, $only_clean = false ) {
	$current_dir = opendir( $dir );
	//$old_umask = umask(0);
	while ($entryname = readdir( $current_dir )) {
		if ($entryname != '.' and $entryname != '..') {
			if (is_dir( $dir . $entryname )) {
				deldir( mosPathName( $dir . $entryname ) );
			} else {
                //@chmod($dir . $entryname, 0777);
				unlink( $dir . $entryname );
			}
		}
	}
	//umask($old_umask);
	closedir( $current_dir );
	if (!$only_clean) {
		return rmdir( $dir );
	} else {
		return true;
	}
}
function jh_copyUploadDirr($fromDir,$toDir) {
	$errors=array();
	$messages=array();
	if (!is_writable($toDir)) {
		$errors[]='target '.$toDir.' is not writable';
	}
	if (!is_dir($toDir)) {
		$errors[]='target '.$toDir.' is not a directory';
	}
	if (!is_dir($fromDir)) {
		$errors[]='source '.$fromDir.' is not a directory';
	}
	if (!empty($errors))
	{
		return false;
	}

	$exceptions=array('.','..','JLMS_intro.swf');

	$handle=opendir($fromDir);
	while (false!==($item=readdir($handle)))
	if (!in_array($item,$exceptions))
	{

		$from=str_replace('//','/',$fromDir.'/'.$item);
		$to=str_replace('//','/',$toDir.'/'.$item);
		if (is_file($from))
		{
			if (@copy($from,$to))
			{
				/*chmod($to,$chmod);*/
				touch($to,filemtime($from));
				$messages[]='File copied from '.$from.' to '.$to;
			}
			else
			$errors[]='cannot copy file from '.$from.' to '.$to;
		}
		if (is_dir($from))
		{
			if (@mkdir($to))
			{
				/*chmod($to,$chmod);*/
				$messages[]='Directory created: '.$to;
			}
			else
			$errors[]='cannot create directory '.$to;
			jh_copyUploadDirr($from,$to);
		}
	}
	closedir($handle);
	return true;
}
function jh_KeepDB() {
	global $joomla_old;
	if ($joomla_old) {
		global $database;
	} else {
		$database = & JFactory::getDBO();
	}
	$query = "SELECT * FROM #__components LIMIT 0,1";
	$database->SetQuery( $query );
	$database->query();
	if ($database->geterrormsg()) {
		sleep(1);
		global $mainframe;
		$database->database( $mainframe->getCfg('host'), $mainframe->getCfg('user'), $mainframe->getCfg('password'), $mainframe->getCfg('db'), $mainframe->getCfg('dbprefix') );
	}
}
?>